home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 8.6 KB | 386 lines | [TEXT/CWIE] |
- // ===========================================================================
- // COutlineTableApp.cp ©1997 Metrowerks Inc. All rights reserved.
- // Original author: John C. Daub
- // ===========================================================================
- // Demonstration application for the PowerPlant "Outline Table" classes (part
- // of the Constructor Additions).
- //
- // This file defines the application object. Based upon the Basic PP project
- // stationery.
-
- #include "COutlineTableApp.h"
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <LDragAndDrop.h>
- #include <UModalDialogs.h>
- #include <LCaption.h>
- #include <UEnvironment.h>
-
- #include <LGADialog.h>
- #include <LScrollerView.h>
- #include <LWindowHeader.h>
- #include <LPopupButton.h>
- #include <LPushButton.h>
- #include <LScrollBar.h>
- #include <LAMPushButtonImp.h>
- #include <LAMControlImp.h>
- #include <LAMPopupButtonImp.h>
- #include <LAMTrackActionImp.h>
- #include <LGAPushButtonImp.h>
- #include <LGAWindowHeaderImp.h>
- #include <LGAPopupButtonImp.h>
- #include <LStdScrollBarImp.h>
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #include "COutlineTable.h"
- #include "CEditTable.h"
-
- Handle gOnIcon = nil;
- Handle gOffIcon = nil;
-
- Int16 gVolIndex = 1; // this is a lame way to do this, but it works....
-
- // some constants
-
- const ResIDT PPob_TableWindow = 1;
- const ResIDT PPob_SelectVolDialog = 128;
- const PaneIDT VolDlg_Popup = 'VOLp';
- const ResIDT MENU_Volume = 1000;
-
- const ResIDT PPob_EditTable = 129;
-
- const CommandT cmd_ShowVolume = 'bRsR';
- const CommandT cmd_EditTable = 'edTB';
-
-
- // and a prototype
-
- static void BuildVolumeMenu(ResIDT menuID);
-
- extern pascal OSErr GetResourceIcons(
- Handle *theSuite,
- /* --> */ short theID,
- /* --> */ long theSelector);
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3);
- UQDGlobals::InitializeToolbox(&qd);
-
- // outline tables support drag and drop, so it's good to ensure
- // it's present before we go any further
-
- if (!LDropArea::DragAndDropIsPresent()) {
- //::StopAlert(ALRT_NoDragAndDrop, nil);
- ::SysBeep(3);
- ::ExitToShell();
- }
-
- UEnvironment::InitEnvironment();
-
- new LGrowZone(20000);
-
- COutlineTableApp theApp;
- theApp.Run();
- }
-
-
- // ---------------------------------------------------------------------------
- // • COutlineTableApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- COutlineTableApp::COutlineTableApp()
- {
- // since we use a popup button and there are problems in the
- // Appearance Manager 1.0 with popup buttons, we'll only use
- // AM implementations if we're under at least Appearance
- // 1.0.1 or later, else use GA implementations.
-
- bool hasAM = UEnvironment::HasFeature(env_HasAppearance101);
- if ( hasAM ) {
- ::RegisterAppearanceClient();
- }
-
-
- // Register functions to create core PowerPlant classes
-
- RegisterClass_(LWindow);
- RegisterClass_(LCaption);
-
- RegisterClass_(COutlineTable);
- RegisterClass_(CEditTable);
-
- RegisterClass_(LGADialog);
- RegisterClass_(LScrollerView);
-
- RegisterClass_(LWindowHeader);
- RegisterClass_(LPopupButton);
- RegisterClass_(LPushButton);
- RegisterClass_(LScrollBar);
-
- if ( hasAM )
- {
- RegisterClassID_(LAMPushButtonImp, LPushButton::imp_class_ID);
- // RegisterClassID_(LAMControlImp, LWindowHeader::imp_class_ID);
- RegisterClassID_(LGAWindowHeaderImp, LWindowHeader::imp_class_ID);
- RegisterClassID_(LAMPopupButtonImp, LPopupButton::imp_class_ID);
- RegisterClassID_(LAMTrackActionImp, LScrollBar::imp_class_ID);
- }
- else
- {
- RegisterClassID_(LGAPushButtonImp, LPushButton::imp_class_ID);
- RegisterClassID_(LGAWindowHeaderImp, LWindowHeader::imp_class_ID);
- RegisterClassID_(LGAPopupButtonImp, LPopupButton::imp_class_ID);
- RegisterClassID_(LStdScrollBarImp, LScrollBar::imp_class_ID);
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~COutlineTableApp
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- COutlineTableApp::~COutlineTableApp()
- {
- if (gOnIcon)
- {
- ::DisposeHandle(gOnIcon);
- }
-
- if (gOffIcon)
- {
- ::DisposeHandle(gOffIcon);
- }
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
-
- void
- COutlineTableApp::StartUp()
- {
- OSErr err = noErr;
-
- err = GetResourceIcons(&gOnIcon, 129, kSelectorAllAvailableData);
- ::DetachResource(gOnIcon);
-
- err = GetResourceIcons(&gOffIcon, 128, kSelectorAllAvailableData);
- ::DetachResource(gOffIcon);
-
- ObeyCommand(cmd_ShowVolume, nil);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
-
- Boolean
- COutlineTableApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- case cmd_ShowVolume:
- {
- DoVolumeTable();
- break;
- }
-
-
- case cmd_EditTable:
- {
- DoEditTable();
- break;
- }
-
-
- default:
- {
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
- }
-
- return cmdHandled;
- }
-
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
-
- void
- COutlineTableApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- case cmd_ShowVolume:
- {
- outEnabled = true;
- break;
- }
-
-
- case cmd_EditTable:
- {
- outEnabled = true;
- break;
- }
-
- default:
- {
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • BuildVolumeMenu
- // ---------------------------------------------------------------------------
- // Construct a menu containing the names of the available volumes.
- // Taken from the "PP CatSearch" demo
-
- static void BuildVolumeMenu(ResIDT menuID)
- {
- MenuHandle volMenu = GetMenu(menuID);
-
- // make sure the menu is empty
- while (::CountMItems(volMenu) > 0) {
- ::DeleteMenuItem(volMenu, 1);
- }
-
- // set up the pb
- HParamBlockRec pb;
- Str31 volName;
-
- pb.volumeParam.ioNamePtr = volName;
- pb.volumeParam.ioVolIndex = 1; // start at the first (there should
- // always be at least one, else how'd you boot?)
-
- OSErr err;
-
- do {
-
- // get info
- err = ::PBHGetVInfoSync(&pb);
-
- if (err == noErr) {
- // this is the proper technique for dealing with metacharacters
- ::AppendMenu(volMenu, "\pdummy");
- ::SetMenuItemText(volMenu, pb.volumeParam.ioVolIndex, volName);
- }
-
- // and move to the next volume in the VCB queue
-
- ++pb.volumeParam.ioVolIndex;
-
- } while (err == noErr);
- }
-
-
- void
- COutlineTableApp::DoVolumeTable()
- {
- #if 000000
- {
- // make the volume menu. This way the MENU resource is
- // already in memory, so when the PPob loads it, it'll use the
- // copy already in memory and things work magically :)
-
- BuildVolumeMenu( MENU_Volume );
-
- // do the volume selection dialog
-
- StDialogHandler theHandler( PPob_SelectVolDialog, this );
- LWindow *theDialog = theHandler.GetDialog();
- // LGAPopup *theMenu = dynamic_cast<LGAPopup*>
- LPopupButton *theMenu = dynamic_cast<LPopupButton*>
- (theDialog->FindPaneByID(VolDlg_Popup));
- ThrowIfNil_(theMenu);
-
- theDialog->Show();
-
- MessageT theMessage;
-
- do {
- theMessage = theHandler.DoDialog();
- } while ( (theMessage != msg_OK) && (theMessage != msg_Cancel) );
-
- if ( theMessage == msg_OK ) {
- gVolIndex = theMenu->GetValue();
- } else {
- return;
- }
-
- }
- #endif
-
- // if OK, we create the "browser" table window
-
- LWindow *theWindow;
- theWindow = LWindow::CreateWindow(PPob_TableWindow, this);
- ThrowIfNil_(theWindow);
-
- #if 0
- // get the volume name of the first volume in the VCB queue (this is
- // what we will use as the window's title). See IM:Files for more info.
-
- HParamBlockRec pb;
- Str31 volName;
- pb.volumeParam.ioNamePtr = volName;
- pb.volumeParam.ioVolIndex = gVolIndex;
-
- ::PBHGetVInfoSync( &pb );
- #endif
-
- // set the window's title to the volume name
-
- theWindow->SetDescriptor( "\pInterim Executive Decision" );
-
- theWindow->Show();
- }
-
- void
- COutlineTableApp::DoEditTable()
- {
- LWindow *theWindow;
- theWindow = LWindow::CreateWindow( PPob_EditTable, this );
- ThrowIfNil_(theWindow);
-
- theWindow->Show();
- }